home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Sound / Sound Utilities / The Sound-Tracker V1.0 / Simple Trecker.c < prev    next >
C/C++ Source or Header  |  1992-05-01  |  5KB  |  134 lines

  1.  
  2. /* Simple Trecker.c */
  3.  
  4. /* Demonstrationsprogramm für die Anwendung der 'PSyn'- und die 'STrI'-Resource. */
  5.  
  6. /* Program to demonstrate the use of the 'PSyn' and 'STrI' resources. */
  7.  
  8. /*
  9.    Copyright (c) 1992 by
  10.       Frank Seide
  11.       Koolbarg 39d
  12.       D-2000 Hamburg 74
  13.       Germany
  14. */
  15.  
  16. /*
  17.    Die 'PSyn'- und die 'STrI'-Resource sowie dieser Beispielquelltext dürfen gerne
  18.    in Public-Domain-Software unter folgenden Bedingungen kostenlos verwendet werden:
  19.    • die Musikroutinen sind nicht frei von Uhrheberrechten. Daher muß
  20.      sich im Public-Domain-Programm und in der Dokumentation ein Hinweis auf das
  21.      Copyright der beiden Resourcen unter Angabe meiner Adresse befinden;
  22.    • ein Exemplar des Programms wird mir zugeschickt;
  23.    • die Resourcen dürfen nicht verändert werden (entdeckte Bugs bitte mir mitteilen;
  24.      ich werde sie dann beheben. Es ist wichtig, einen Versionswildwuchs zu vermeiden);
  25.    • eine kommerzielle Nutzung ist nur nach meiner ausdrücklichen, schriftlichen
  26.      Zustimmung zulässig, sonst nicht.
  27. */
  28.  
  29. /*
  30.    The 'PSyn' and 'STrI' resources as well as this example source code may be used
  31.    freely in public domain programs under the following conditions:
  32.    • the resources themselves are copyrighted and not in the public domain!
  33.      The public domain program and the documentation must contain a copyright notice
  34.      like above, my address must be mentioned;
  35.    • you must send me one copy of the program;
  36.    • the code resources may not be modified (if you should find a bug, please tell me
  37.      to fix it. It´s important not to have too many different versions of the code);
  38.    • any kind of commercial use is forbidden and requires a special license aggreement.
  39. */
  40.  
  41. #include <stdio.h>
  42. #include <sound.h>
  43. #include "PSyn.h"
  44. #include "STrI.h"
  45.  
  46. main()
  47. {
  48.     /* Das Programm benötigt den Sound-Manager von System 7 (den enthält auch System */
  49.     /* 6.0.7) und einen MC68020 (oder höher). Die 'PSyn'-Resource überprüft dies beim */
  50.     /* Öffnen des Sound-Kanals. Es ist jedoch sinnvoll, diese Überprüfung am Anfang */
  51.     /* des Hauptprogramms selbst durchzuführen (wird in diesem Beispiel nicht getan). */
  52.     
  53.     /* The program requires the sound manager of System 7 (contained in System 6.0.7 */
  54.     /* and above) and a MC68020 (or higher). The 'PSyn' code performs a check before */
  55.     /* opening the sound channel. You may want to do this check in the main program
  56.     /* (not shown in this example). */
  57.  
  58.     /* Variablen / Variables: */
  59.     int i;
  60.     struct PChannel * pc = NULL;        /* Pointer */
  61.     struct SoundTrack ** strk = NULL;    /* Handle! */
  62.  
  63.     /* Konstanten / Constants: */
  64.     Boolean stereo = FALSE;            /* Stereo ? */
  65.     Boolean fadeOut = TRUE;            /* Beim Stoppen ausblenden / fade out on stop ? */
  66.  
  67.     /* Initialisierungen / Initializations: */
  68.  
  69.     InitGraf (&thePort);
  70.     InitFonts();
  71.     FlushEvents (everyEvent, 0);
  72.     InitWindows();
  73.     InitMenus();
  74.     TEInit();
  75.     InitDialogs (NULL);
  76.      InitCursor();
  77.      
  78.     /* Soundkanal öffnen / Open the sound channel: */
  79.     if (OpenPChannel (CHANNELS, stereo, 445*2, &pc)) { SysBeep (30); exit(); }
  80.     
  81.     /* Wiedergabeabtastrate auf 22 kHz setzen (Default; nur zur Demonstration): */
  82.     /* Change output sampling rate to 22 kHz (default; just to demonstrate): */
  83.     pc->softFreq = pc->hardFreq = rate22khz;
  84.  
  85.     /* Maximale Lautstärke für die 4 Stimmen, 50% Gesamtlautstärke: */    
  86.     /* Maximum volume for the four voices, 50% total volume: */
  87.     for (i = 0; i < 4; i++) PChannelVolume (pc, i, 0x10000);
  88.     PChannelVolume (pc, -1, 0x08000);    /* -1 = Gesamtlautstärke / Total volume */
  89.     
  90.     /* Hauptschleife / Main Loop: */
  91.     while (TRUE) {
  92.     
  93.         /* Open-Dialog präsentieren / Show open dialog: */
  94.         Point openPoint = { 85, 100 };
  95.         SFTypeList theTypeList = { 'STrk' };
  96.         SFReply theReply;
  97.         
  98.         SFGetFile (openPoint, "\p", NULL, 1, theTypeList, NULL, &theReply);
  99.         if (!theReply.good) { StopPChannel (pc, fadeOut); break; }
  100.         
  101.         /* Laufenden SoundTrack abschalten / Stop currently playing SoundTrack: */
  102.         if (strk) {
  103.             StopPChannel (pc, fadeOut);        /* Stoppen / stop playing */
  104.             UnlinkSoundTrack (strk);        /* STrk abtrennen / Unlink STrk from chan */
  105.             DisposeSoundTrack (strk);        /* Speicher freigeben / free memory */
  106.             strk = NULL;
  107.         }
  108.         
  109.         /* Neuen SoundTrack laden / Load next SoundTrack: */
  110.         if (GetSoundTrack (theReply.vRefNum, theReply.fName, 0, &strk, FALSE))
  111.             SysBeep (30);
  112.         else {
  113.             /* SoundTrack-Optionen einstellen / Change SoundTrack options: */
  114.             (*strk)->musicRecord.loopDetect = TRUE;
  115.             
  116.             /* Soundtrack mit Kanal verbinden / Link STrk to sound channel: */
  117.             LinkSoundTrack (strk, pc);
  118.             
  119.             /* Kanaloptionen setzen / Change channel options: */
  120.             pc->antiAlias = TRUE;
  121.             PChannelVolume (pc, -1, 0x08000);    /* Nötig! / Necessary due to fadeOut */
  122.             
  123.             /* Stück von vorne spielen / Play SoundTrack from start: */
  124.             ResetPChannel (pc);
  125.             if (StartPChannel (pc)) { SysBeep (30); break; }
  126.         }
  127.     }
  128.     
  129.     /* Soundkanal schließen (unbedingt nötig bei System 6.0.7!): */
  130.     /* Close the sound channel (necessary on System 6.0.7!): */    
  131.     ClosePChannel (pc);
  132. }
  133.  
  134.